const { Sequelize } = require("sequelize");
const {
  MYSQL_ADDRESS,
  MYSQL_PASSWORD,
  MYSQL_USERNAME,
} = require("../config/config.default");

const [host, port] = MYSQL_ADDRESS.split(":");

const seq = new Sequelize("lotter", MYSQL_USERNAME, MYSQL_PASSWORD, {
  host,
  port,
  dialect: "mysql",
});

seq
  .authenticate()
  .then(() => {
    console.log("数据库连接成功！");
  })
  .catch((err) => {
    console.error("数据库连接成失败:", err);
  });

module.exports = seq;
